# Default Dockerfile
#
# @link     https://www.hypercmf.com
# @document https://hyperf.wiki
# @contact  forpastime@qq.com
# @license

FROM hyperf/hyperf:7.4-alpine-v3.11-swoole
LABEL maintainer="HyperCMF <forpastime@qq.com>" version="1.0" license="MIT" app.name="HyperCMF"

##
# ---------- env settings ----------
##
# --build-arg timezone=Asia/Shanghai
ARG timezone

ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \
    APP_ENV=prod \
    SCAN_CACHEABLE=(false)

# update
RUN set -ex \
    # show php version and extensions
    && php -v \
    && php -m \
    && php --ri swoole \
    #  ---------- some config ----------
    && cd /etc/php7 \
    # - config PHP
    && { \
        echo "upload_max_filesize=128M"; \
        echo "post_max_size=128M"; \
        echo "memory_limit=1G"; \
        echo "date.timezone=${TIMEZONE}"; \
    } | tee conf.d/99_overrides.ini \
    # - config timezone
    && ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
    && echo "${TIMEZONE}" > /etc/timezone \
    # ---------- clear works ----------
    && rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
    && echo -e "\033[42;37m Build Completed :).\033[0m\n"

WORKDIR /opt/www/
#/docker/hyperf/hyperf-skeleton/

# Composer Cache
# COPY ./composer.* /opt/www/
# RUN composer install --no-dev --no-scripts

######### 使用源码
# 复制所有文件到指定目录后直接运行
# 如果是通过phar打包后，就不用下面COPY命令，同时最后 的 ENTRYPOINT命令修改为执行 php hypercmf.phar start
COPY . /opt/www

RUN cd /opt/www/ && php bin/hyperf.php

EXPOSE 9501

ENV LANG=zh_CN.UTF-8 LANGUAGE=zh_CN:zh LC_ALL=zh_CN.UTF-8

ENTRYPOINT ["php", "/opt/www/bin/hyperf.php", "start"]
#########

######### 使用打包
# 把宿主机的jdk安装压缩包复制到镜像中，安装包必须与dockerfile同级目录，该命令会自动解压tar压缩包
#ADD hypercmf.phar /opt/www/
#EXPOSE 9501
#ENV LANG=zh_CN.UTF-8 LANGUAGE=zh_CN:zh LC_ALL=zh_CN.UTF-8
#ENTRYPOINT ["php", "hypercmf.phar", "start"]


## 容器启动命令
#docker run --privileged=true  -v /www/demo.hypercmf.com:/opt/www/ -p 8088:9501 -p 9503:9503 -p 9512:9512 --name=hypercmf -it hypercmf:1.0

## 打包时挂载配置文件启动容器命令
#docker run --privileged=true -v /www/docker/hypercmf/.env:/opt/www/.env -p 8088:9501 -p 9503:9503 -p 9512:9512 --name=hypercmf -it hypercmf:1.0